<template>
	<div class="outerFrame">
		<el-form ref="form" label-width="150px">
			<el-row>
				<el-col :span="12">
					<div
						style="
				font-size: 30px;
				font-weight: bold;
				margin: 30px 0 30px 150px;"
					>
						网站设置
					</div>
					<el-form-item :label="item.name" v-for="(item, index) in request.data" v-if="item.type == 2">
						<el-upload v-if="item.dkey == 'icon'" class="avatar-uploader" action="#" :show-file-list="false" :auto-upload="false" :on-change="changeImg">
							<img v-if="item.dvalue" :src="item.dvalue" class="avatar" style="width: 70px;height: 70px;" />
							<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>
						<el-input v-else v-model="item.dvalue"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<div
						style="
				font-size: 30px;
				font-weight: bold;
				margin:  30px 0 30px 150px;"
					>
						邮箱设置
					</div>
					<el-form-item :label="item.name" v-for="(item, index) in request.data" v-if="item.type == 3"><el-input v-model="item.dvalue"></el-input></el-form-item>
				</el-col>
			</el-row>
			<el-form-item><el-button type="primary" @click="update" v-hasPermission="'00000035'">保存</el-button></el-form-item>
		</el-form>
	</div>
</template>
<script>
import utils from 'util/utils.js';
import api from 'api/system/systemsetting/systemsetting.js';
export default {
	name: 'systemsetting',
	data() {
		return {
			loading: true,
			request: utils.newRequest()
		};
	},
	methods: {
		//获取数据
		list() {
			this.loading = true;
			api.list(this.request, response => {
				this.request.data = response.data;
				this.loading = false;
			});
		},
		update() {
			this.loading = true;
			api.update(this.request, response => {
				utils.msg.success(response.msg);
				this.loading = false;
				this.list();
			});
		},
		getBase64(file) {
			return new Promise(function(resolve, reject) {
				let reader = new FileReader();
				let imgResult = '';
				reader.readAsDataURL(file);
				reader.onload = function() {
					imgResult = reader.result;
				};
				reader.onerror = function(error) {
					reject(error);
				};
				reader.onloadend = function() {
					resolve(imgResult);
				};
			});
		},
		//选择图片后
		changeImg(file, fileList) {
			for (let data of this.request.data) {
				if (data.dkey == 'icon') {
					this.getBase64(file.raw).then(res => {
						data.dvalue = res;
					});
					break;
				}
			}
		}
	},
	mounted() {
		this.list();
	}
};
</script>

<style lang="scss" scoped="scoped">
@import '~common/custom/css/common.scss';
</style>
